﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using sourcephi.Models;
using Webdiyer.WebControls.Mvc;
using System.IO;

namespace sourcephi.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        //private Models.sourceEntities db = new Models.sourceEntities();//可以用using的方法 这样回收数据比较快
        public ActionResult Index()
        {
            using (sourceEntities db=new sourceEntities())
            {
                List<Models.tongzhi> list = db.tongzhi.Where(s => s.same == "1").OrderByDescending(t => t.addtime).Take(10).ToList();
                return View(list);
            }
            //List<Models.renyuan> list = db.renyuan.Include("dafen").Where(s => s.islock == true).ToList();
        }

        public ActionResult ppwj(int id = 1)
        {
            using (sourceEntities db=new sourceEntities())
            {
                var list = db.tongzhi.Where(s => s.same == "2").OrderByDescending(t => t.addtime).ToPagedList(id, 10);
                return View(list);
            }
            
        }
        public ActionResult DownFile(string filePath, string fileName)
        {
            filePath = Server.MapPath(filePath);
            FileStream fs = new FileStream(filePath, FileMode.Open);
            byte[] bytes = new byte[(int)fs.Length];
            fs.Read(bytes, 0, bytes.Length);
            fs.Close();
            Response.Charset = "UTF-8";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            Response.ContentType = "application/octet-stream";

            Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileName));
            Response.BinaryWrite(bytes);
            Response.Flush();
            Response.End();
            return new EmptyResult();
        }

    }
}
